<template>
	<view class="editInfo">
		<an-nav-bar :title="technicianForm.accountType == '1' ? '技师入驻':'商家入驻'" :navStyle="navStyle">
			<template :slot="'right'">
				<view style="color: #fff;" @click="$refs.refEntryNotice.open()">入驻须知</view>
			</template>
		</an-nav-bar>
		<image class="back" src="/static/editMemberBack.png" mode=""></image>
		<view class="content">
			<view class="avatarBox">
				<view class="avatar">
					<image :src="technicianForm.headImg ? $common.binImage(technicianForm.headImg) :'/static/serve-2.png'" mode=""></image>
				</view>
				<view class="name">{{technicianForm.mobile | geTel}}</view>
				<!-- <view class="btns flex" v-if="technicianForm.accountType == '1'">
					<view class="btn">
						<view class="">上传头像</view>
					</view>
					<view class="btn flex">
						<view class="">真人认证</view>
					</view>
				</view> -->
			</view>
			<view class="albums" v-if="technicianForm.accountType == '2'">
				<view class="title">
					上传营业执照
					<text>（请上传营业执照正反面）</text>
				</view>
				<view class="photos flex">
					<view class="img" @click="choosePhoto">
						<image src="/static/icon_add.png" mode=""></image>
					</view>
					<view class="img" v-for="(item,index) in technicianForm.licenseImg" :key="index" @click.stop="previewImg">
						<view class="clear" @click.stop="deleteImg(index)">
							<uni-icons type="clear" size="30" color="#ff4400"></uni-icons>
						</view>
						<image :src="$common.binImage(item)" mode=""></image>
					</view>
				</view>
			</view>
			<view class="albums" v-if="technicianForm.accountType == '1'">
				<view class="title">
					上传相册
					<text>（至少3张以上本人生活照，其它一律不通过）</text>
				</view>
				<view class="photos flex">
					<view class="img" @click="choosePhoto">
						<image src="/static/icon_add.png" mode=""></image>
					</view>
					<view class="img" v-for="(item,index) in technicianForm.recentPhoto" :key="index" @click.stop="previewImg">
						<view class="clear" @click.stop="deleteImg(index)">
							<uni-icons type="clear" size="30" color="#ff4400"></uni-icons>
						</view>
						<image :src="$common.binImage(item)" mode=""></image>
					</view>
				</view>
			</view>
			<view class="form">
				<view class="line" v-if="technicianForm.accountType == '1'">
					<i class="i1"></i>
					<view class="label">岗位</view>
					<view class="right" @click="jobPosition">
						<span class="span1">{{technicianForm.jobTitle || '未设置'}}</span>
					</view>
				</view>
				<view class="line" v-if="technicianForm.accountType == '1'">
					<i class="i2"></i>
					<view class="label">个性标签</view>
					<view class="right tags" @click="gotoUrl('/pages/my/tags')">
						<template v-if="technicianForm.personLabel.length">
							<text v-for="(item,index) in technicianForm.personLabel" v-if="index < 3"
								:key="index">{{item}}</text>
						</template>
						<span v-else class="span1">未设置</span>
					</view>
				</view>
				<view class="line" v-if="technicianForm.accountType =='1'">
					<i class="i3"></i>
					<view class="label">兴趣爱好</view>
					<view class="right" @click="gotoUrl('/pages/my/hobby')">
						<span class="span1">{{technicianForm.hobbies || '未设置'}}</span>
					</view>
				</view>
				<view class="line" v-if="technicianForm.accountType == '1'">
					<i class="i4"></i>
					<view class="label">个人介绍</view>
					<view class="right" @click="gotoUrl('/pages/my/introduce?type=1')">
						<span class="span1">{{technicianForm.selfIntroduction || '未设置'}}</span>
					</view>
				</view>
				<view class="line" v-if="technicianForm.accountType == '2'">
					<i class="i4"></i>
					<view class="label">门店介绍</view>
					<view class="right" @click="gotoUrl('/pages/my/introduce?type=2')">
						<span class="span1">{{technicianForm.selfIntroduction || '未设置'}}</span>
					</view>
				</view>
				<!-- <view class="line" v-if="technicianForm.accountType == '1'">
					<i class="i5"></i>
					<view class="label">语音认证</view>
					<view class="right">
						<span class="span1">{{technicianForm.voiceLabel || '未设置'}}</span>
					</view>
				</view> -->
				<view class="line" v-if="technicianForm.accountType == '1'">
					<i class="i7"></i>
					<view class="label">设置微信号</view>
					<view class="right" @click="gotoUrl('/pages/my/editWechatNumber?show=1')">
						<span class="span1">{{technicianForm.wecatAccount || '未设置'}}</span>
					</view>
				</view>
				<view class="line" v-if="technicianForm.accountType == '1'">
					<i class="i8"></i>
					<view class="label">我的昵称</view>
					<view class="right" @click="gotoUrl('/pages/my/editNickname?show=1')">
						<span class="span1">{{technicianForm.nickName || '未设置'}}</span>
					</view>
				</view>
				<view class="line" v-if="technicianForm.accountType == '1'">
					<i class="i9"></i>
					<view class="label">性别</view>
					<view class="right" @click="selectSex">
						<span class="span1">{{technicianForm.sex || '未设置' }}</span>
					</view>
				</view>
				<view class="line" v-if="technicianForm.accountType =='1'">
					<i class="i10"></i>
					<view class="label">年龄</view>
					<picker class="right picker-box" @change="bindPickerChange" :range="ageArray">
						<view style="width: 100%;"><span class="span1">{{technicianForm.age || '未设置' }}</span></view>
					</picker>
				</view>
				<view class="line">
					<i class="i11"></i>
					<view class="label">所在区域</view>
					<view class="right" @click="onGetLocation">
						<span class="span1">{{technicianForm.city || '未设置'}}</span>
					</view>
				</view>
				<view v-if="technicianForm.status != 0" class="line">
					<i class="i12"></i>
					<view class="label">实名认证</view>
					<view class="right" @click="gotoUrl('/pages/s/auth/realname')">
						<span class="span1">{{technicianForm.isAuth?'已认证':technicianForm.idCard?'已设置':'未设置'}}</span>
					</view>
				</view>
				<view class="line">
					<i class="i13"></i>
					<view class="label">是否公开</view>
					<view class="right" @click="onOvert">
						<span class="span1">{{technicianForm.publicStatus || '未设置'}}</span>
					</view>
				</view>
			</view>
			
			<view class="bottom">
				<view class="flex2" style="margin: 0 40rpx;">
					<view class="flex-1">
						<button class="button1" @click="goDownload">
							下载{{technicianForm.accountType == '1' ? '技师端':'商家端'}}
						</button>
					</view>
					<view class="flex-0" style="width: 40rpx;"></view>
					<view class="flex-1">
						<template v-if="technicianForm.status == 0">审核中</template>
						<template v-else-if="technicianForm.status == 1">审核通过</template>
						<template v-else-if="technicianForm.status == 2">
							审核不通过
							<!-- <text style="margin-left: 8px; color: #666;">{{technicianForm.remark}}</text> -->
						</template>
						<template v-else>
							<button class="button2" @click="submit">提交审核</button>
						</template>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="browse flex_center">谁看了我</view> -->
		
		
		<!-- 入驻须知 -->
		<uni-popup type="center" ref="refEntryNotice">
			<view class="default-popup">
				<view class="default-popup_close" @click="$refs.refEntryNotice.close()"></view>
				<view class="default-popup_title">入驻须知</view>
				<view style="padding: 0 40rpx; color: #929292;">
					<view>1.审核之前必须先添加运营微信，以便验证资料的真实性，否则不通过。</view>
					<view>2.审核时间周一至周五 9:30~18:30</view>
					
					<view style=" padding: 24rpx 0; text-align: center; color: #333;" @click="$common.doCopy('XXXXX')">运营微信：XXXXX  <text style="margin-left: 20rpx; color: #AA8050;">复制</text></view>
					
					<view style=" margin: 0 auto; width: 240rpx; height: 240rpx;">
						<image class="image" src="/static/image/entry-customer.png"></image>
					</view>
					
					<view style=" padding: 20rpx 0 40rpx; text-align: center;">
						<view>添加运营微信时</view>
						<view>请备注康约到家平台审核</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import indexConfig from '@/config/index.config';
	export default {
		data() {
			return {
				imgUrl:indexConfig.imgUrl,
				ageArray: [],
				navStyle: {
					background: '#171539'
				},
				userInfo: {},
				licenseImgArray: [],
				technicianForm: {
					"city": "",
					"accountType": "1",
					"address": "", //地址
					"mobile": "",
					"age": "", //年龄
					"licenseImg": [],
					"headImg": "",
					"jobTitle": "",
					"hobbies": "",
					"mobile": "",
					"nickName": "",
					"personLabel": [],
					"recentPhoto": [], //相册
					"publicStatus": "",
					"selfIntroduction": "",
					"sex": "",
					"storeId": 0,
					"voiceLabel": "",
					"wecatAccount": "",
					"isAuth": "",
					"longitude": "",
					"latitude": ""
				}
			};
		},
		onLoad(option) {
			this.technicianForm.accountType = option.type + ''
			console.log(this.technicianForm.accountType)
			this.ageArray = Array.from(Array(100), (v, k) => k)
			this.ageArray.splice(0, 18)
		},
		onShow() {
			this.getUser()
		},
		methods: {
			getUser(){
				this.userInfo = this.$mStore.state.userInfo
				this.$http.get(
					`/app/customer/customer/getMassageApplyDetail`, {
						'mobile': this.userInfo.mobile,
						'accountType': this.technicianForm.accountType
					}
				).then(r => {
					if (r.data) {
						this.technicianForm = r.data;
						if (this.technicianForm.licenseImg) {
							this.technicianForm.licenseImg = this.technicianForm.licenseImg.split(",");
						}
						if (this.technicianForm.recentPhoto) {
							this.technicianForm.recentPhoto = this.technicianForm.recentPhoto.split(",");
						}
						if (this.technicianForm.personLabel) {
							this.technicianForm.personLabel = this.technicianForm.personLabel.split(",");
						}
						if (this.technicianForm.publicStatus) {
							this.technicianForm.publicStatus = '是';
						} else {
							this.technicianForm.publicStatus = '否';
						}
					} else {
						this.technicianForm.nickName = this.userInfo.nickName
						this.technicianForm.headImg = this.userInfo.photo
						this.technicianForm.mobile = this.userInfo.mobile
						this.technicianForm.wecatAccount = this.userInfo.wecatAccount
						this.licenseImgArray = []
					}
					console.log(this.technicianForm)
				})
			},
			onGetLocation() {
				let _this = this;
				uni.showLoading({
					title: '位置信息获取中'
				})
				uni.getLocation({
					type: 'wgs84',
					geocode: true,
					success: (res) => {
						uni.hideLoading()
						console.log(res)
						_this.technicianForm.longitude = res.longitude
						_this.technicianForm.latitude = res.latitude
						_this.$http.get(
							`/appNoAuth/store/massageTechnician/getAddress/${res.longitude}/${res.latitude}`
						).then(r => {
							let {
								result
							} = JSON.parse(r.data)
							_this.technicianForm.address = result.address
							_this.technicianForm.city = result.address_component.city
						})
					},
					fail: function() {
						uni.hideLoading()
						uni.showToast({
							title: '获取地址失败，将导致部分功能不可用',
							icon: 'none'
						});
					}
				})
			},
			deleteImg(idx) {
				if (this.technicianForm.accountType == 1) {
					this.technicianForm.recentPhoto.splice(idx, 1)
				} else {
					this.technicianForm.licenseImg.splice(idx, 1)
				}
			},
			// 预览图片多张
			previewImg(index) {
				let _this = this;
				let imgsArray = [];
				if (this.technicianForm.accountType == 1) {
					for (let i = 0; i < this.technicianForm.recentPhoto.length; i++) {
						if (this.technicianForm.recentPhoto[i]) {
							imgsArray.push(this.imgUrl+this.technicianForm.recentPhoto[i]);
						}
					}
				} else {
					for (let i = 0; i < this.technicianForm.licenseImg.length; i++) {
						if (this.technicianForm.licenseImg[i]) {
							imgsArray.push(this.imgUrl+this.technicianForm.licenseImg[i]);
						}
					}
				}
				// #ifdef MP
				uni.previewImage({
					current: index - 1,
					urls: imgsArray,
					indicator: 'number',
					loop: true
				});
				// #endif

				// #ifndef MP
				uni.previewImage({
					current: index - 1,
					urls: imgsArray,
					indicator: 'number',
					loop: true
				});
				// #endif
			},
			choosePhoto() {
				const _this = this;
				uni.chooseImage({
					count: 3, //最多可以选择的图片张数，默认9
					sourceType: ['album',
						"camera"
					], //album 从相册选图，camera 使用相机，默认二者都有。如需直接开相机或直接选相册，请只使用一个选项
					sizeType: ['compressed'], //original 原图，compressed 压缩图，默认二者都有
					success(res) {
						if (res.tempFilePaths) {
							res.tempFilePaths.forEach((item) => {
								_this.uploadPhoto(item)
							})
						}
					},
					fail() {
						console.log('失败', err);
					},
					complete() {
						console.log('结束');
					},
				})
			},
			uploadPhoto(path) {
				this.$http.upload('/app/common/upload', {
					filePath: path,
					name: 'file'
				}).then(res => {
					console.log(res)
					if (this.technicianForm.accountType == 1) {
						this.technicianForm.recentPhoto.push(res.fileName)
					} else {
						this.technicianForm.licenseImg.push(res.fileName)
						this.licenseImgArray.push(res.fileName)
					}
					console.log(this.licenseImgArray)
					uni.hideLoading()
				}).catch(err => {
					uni.hideLoading()
				})
			},
			jobPosition() {
				let sexArr = ['按摩', '健身',]
				uni.showActionSheet({
					itemList: sexArr,
					success: (res) => {
						this.technicianForm.jobTitle = sexArr[res.tapIndex]
					},
					fail: (res) => {
						console.log(res.errMsg);
					}
				});
			},
			onOvert() {
				let sexArr = ['是', '否']
				uni.showActionSheet({
					itemList: sexArr,
					success: (res) => {
						this.technicianForm.publicStatus = sexArr[res.tapIndex]
					},
					fail: (res) => {
						console.log(res.errMsg);
					}
				});
			},
			selectSex() {
				let sexArr = ['男', '女']
				uni.showActionSheet({
					itemList: sexArr,
					success: (res) => {
						this.technicianForm.sex = sexArr[res.tapIndex]
					},
					fail: (res) => {
						console.log(res.errMsg);
					}
				});
			},
			bindPickerChange(e) {
				this.technicianForm.age = this.ageArray[e.detail.value]
			},
			gotoUrl(url) {
				console.log(url)
				uni.navigateTo({
					url: url
				})
			},
			submit() {
				if (this.technicianForm.status == '1') {
					return;
				}
				let form = JSON.parse(JSON.stringify(this.technicianForm))
				form.personLabel = form.personLabel?form.personLabel.join(','):''
				form.recentPhoto = form.recentPhoto?form.recentPhoto.join(','):''
				form.licenseImg = form.licenseImg?form.licenseImg.join(','):''
				// if(form.accountType == '1'){
				// 	this.$delete(form, 'licenseImg');
				// }
				// form.recentPhoto = form.licenseImg.join(',')
				form.publicStatus = form.publicStatus == '是' ? true : false
				form.status = '0';
				if (form.id) {
					this.$http.post('/app/customer/customer/updateMassageTechnician', form).then(res => {
						uni.showToast({
							title: '提交成功',
							icon: 'error'
						})
						uni.switchTab({
							url: '/pages/tabbar/my'
						})
					})
				} else {
					this.$http.post('/app/customer/customer/addMassageTechnician', form).then(res => {
						uni.showToast({
							title: '提交成功',
							icon: 'error'
						})
						uni.switchTab({
							url: '/pages/tabbar/my'
						})
					})
				}
			},
			goDownload() {
				//#ifdef H5
				location.href = indexConfig.hostJsUrl+'/dl/';
				//#endif
			
				//#ifdef APP-PLUS
				plus.runtime.openURL(indexConfig.hostJsUrl+'/dl/');
				//#endif
			},
		}
	}
</script>

<style lang="scss" scoped>
	.editInfo {
		background: #f8f8f8;
		min-height: 100vh;

		.bottom {
			position: fixed;
			left: 0;
			bottom: 0;
			padding: 20rpx 0;
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			color: #aa8050;
			background: #fff;

			button {
				width: 100%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				border: 1rpx solid #aa8050;
				border-radius: 48rpx;
				font-size: 30rpx;
			}
			
			.button1{
				color: #aa8050;
				background: #fff;
			}
			.button2{
				color: #fff;
				background: #aa8050;
			}
		}

		.form {
			position: relative;
			padding-bottom: 158rpx;

			.line {
				display: flex;
				align-items: center;
				padding: 0 30rpx;
				background: #fff;
				height: 100rpx;
				border-bottom: 2rpx solid #eee;
				width: 100%;
				box-sizing: border-box;

				.tags {
					text {
						display: block;
						min-width: 110rpx;
						box-sizing: border-box;
						padding: 0 10rpx;
						height: 52rpx;
						line-height: 52rpx;
						border-radius: 26rpx;
						border: 2px solid #afa1ff;
						color: #afa1ff;
						font-size: 26rpx;
						text-align: center;
						margin-left: 10rpx;
					}
				}

				.picker-box {
					display: block;
					width: 100%;
				}

				.right {
					flex: 1;
					display: flex;
					align-items: center;
					justify-content: flex-end;
					font-size: 30rpx;
					margin-left: 30rpx;
					text-align: right;

					.span1 {
						color: #999;
						width: 100%;
						max-width: 420rpx;
						display: inline-block;
						text-align: right;
						word-break: keep-all;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					&::after {
						content: "";
						display: block;
						background: url(/static/grey-arrow-right.png) no-repeat;
						background-size: 100% auto;
						width: 6px;
						height: 11px;
						margin-left: 10px;
						transform: translateY(1px);
					}
				}

				.label {
					color: #333;
					font-size: 30rpx;
				}

				>i {
					display: block;
					width: 38rpx;
					height: 42rpx;
					margin-right: 12rpx;
				}

				.i1 {
					background: url(/static/makeFriends1.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i2 {
					background: url(/static/makeFriends2.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i3 {
					background: url(/static/makeFriends3.png) no-repeat 50%;
					background-size: 36rpx auto;
				}

				.i4 {
					background: url(/static/makeFriends4.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i5 {
					background: url(/static/makeFriends5.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i1 {
					background: url(/static/makeFriends1.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i6 {
					background: url(/static/makeFriends6.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i7 {
					background: url(/static/makeFriends7.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i8 {
					background: url(/static/makeFriends8.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i9 {
					background: url(/static/makeFriends9.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i10 {
					background: url(/static/makeFriends10.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i11 {
					background: url(/static/makeFriends11.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i12 {
					background: url(/static/makeFriends12.png) no-repeat 50%;
					background-size: 38rpx auto;
				}

				.i13 {
					background: url(/static/makeFriends13.png) no-repeat 50%;
					background-size: 38rpx auto;
				}
			}
		}

		.albums {
			padding: 0 30rpx;
			background: #fff;
			border-bottom: 10rpx solid #eee;
			position: relative;

			.title {
				color: #333;
				font-size: 30rpx;
				white-space: nowrap;
				padding-top: 10rpx;

				text {
					color: #666;
					font-size: 24rpx;
				}
			}

			.photos {
				padding: 20rpx 0 22rpx;
				flex-wrap: wrap;

				.img {
					margin-right: 10rpx;
					position: relative;

					&:nth-child(3n + 3) {
						margin-right: 0;
					}

					.clear {
						position: absolute;
						right: 0;
						top: 0;
						z-index: 99;
					}

					image {
						width: 222rpx;
						height: 222rpx;
						border-radius: 10rpx;
						overflow: hidden;
					}
				}
			}
		}

		.avatarBox {
			text-align: center;
			overflow: hidden;
			background: #fff;

			.btns {
				padding: 10rpx 0 26rpx;
				border-bottom: 2rpx solid #eee;
				position: relative;
				background: #fff;

				.btn {
					flex: 1;
					overflow: hidden;
					padding: 0 7px;

					>view {
						float: right;
						display: flex;
						align-items: center;
						justify-content: center;
						width: 180rpx;
						height: 60rpx;
						border-radius: 15px;
						border: 2rpx solid #ccc;
						color: #999;
						font-size: 30rpx;
						box-sizing: border-box;
						cursor: pointer;
					}

					&:first-child>view {
						color: #9f50f3;
						border: 2rpx solid #9f50f3;
					}
				}
			}

			.name {
				color: #000;
				font-size: 32rpx;
				font-weight: 700;
				position: relative;
				background: #fff;
				margin-top: 10rpx;
				line-height: 40rpx;
			}

			.avatar {
				display: block;
				width: 160rpx;
				height: 160rpx;
				box-shadow: 0 0 10rpx 0 rgba(0, 0, 0, .5);
				border-radius: 50%;
				margin: 100rpx auto 0;
				position: relative;

				image {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}
		}

		.browse {
			width: 150rpx;
			height: 60rpx;
			background: linear-gradient(90deg, #d7b075, #aa8050);
			border-radius: 28rpx 0 0 28rpx;
			position: fixed;
			right: 0;
			top: 248rpx;
			font-size: 26rpx;
			font-weight: 400;
			color: #fff;
		}

		.back {
			position: fixed;
			left: 0;
			top: 88rpx;
			width: 100%;
			height: 242rpx;
		}
	}
</style>
